//
//  LandingViewController.m
//  WebPDA
//
//  Created by Justin Yip on 8/20/10.
//  Copyright 2010 TenNights.com. All rights reserved.
//

#import "LandingViewController.h"
#import "UIViewController+AutoAdjust.h"

@implementation LandingViewController
@synthesize tableView;
@synthesize formTable;

-(IBAction)login:(id)sender {
	/*
	MainViewController *mainViewCtrl = [[MainViewController alloc] initWithSmartNib];
	[self presentModalViewController:mainViewCtrl animated:YES];
	[mainViewCtrl release];
	 */
	
	[self.view removeFromSuperview];
}

- (void)keyboardDidShow:(NSNotification*)notif {
	
	NSDictionary *userInfo = [notif userInfo];
	NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];
	CGSize keyboardSize = [aValue CGRectValue].size;
	
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
	[UIView setAnimationDuration:0.2];
	
	CGRect rect = self.view.frame;
	rect.origin.y -= keyboardSize.height;
	self.view.frame = rect;
	
	[UIView commitAnimations];
	
}

- (void)keyboardWillHide:(NSNotification*)notif {
	
	NSDictionary *userInfo = [notif userInfo];
	NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];
	CGSize keyboardSize = [aValue CGRectValue].size;
	
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
	[UIView setAnimationDuration:0.3];
	
	CGRect rect = self.view.frame;
	rect.origin.y += keyboardSize.height;
	self.view.frame = rect;
	
	[UIView commitAnimations];
}

#pragma mark -
#pragma mark View lifecycle


- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
	
	//FIXME: this is a deprecated property
	//deprecated in os3.2
	tableView.backgroundColor = [UIColor clearColor];//for iphone
	//remove the backgroundView for ipad
	tableView.backgroundView = nil;
	
	[formTable loadBundle:@"LoginForm"];
}

- (void)viewWillAppear:(BOOL)animated {
	[super viewWillAppear:animated];
	
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)viewWillDisappear:(BOOL)animated {
	[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return NO;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
	
}

#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}


- (void)dealloc {
	[tableView release];
	[formTable release];
    [super dealloc];
}


@end

